//
//  TianPowerful.c
//  btvideo
//
//  Created by Jason on 2021/8/23.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

#include "TianPowerful.h"
#import <sys/stat.h>
#import <dlfcn.h>
#import <stdlib.h>
#include <string.h>

void disable_gdb(void) {
   void* handle = dlopen(0, RTLD_GLOBAL | RTLD_NOW);
   ptrace_ptr_t ptrace_ptr = dlsym(handle, "ptrace");
   ptrace_ptr(PT_DENY_ATTACH, 0, 0, 0);
   dlclose(handle);
}



void checkCydia(void)
{
    struct stat stat_info;
    if (0 == stat("/Applications/Cydia.app", &stat_info)) {
//        printf("Device is jailbroken \n");
        
        exit(0);
    }else{
//        printf("Device is passed \n");
    }
}


 
void checkInject(void)
{
    checkCydia();
    
    int ret ;
    Dl_info dylib_info;
    int    (*func_stat)(const char *, struct stat *) = stat;
    if ((ret = dladdr(func_stat, &dylib_info))) {
        
        const char* str = "/usr/lib/system/libsystem_kernel.dylib";
        
        if (strcmp(dylib_info.dli_fname, str) != 0) {
//            printf("Device [checkInject] is jailbroken \n");
            exit(0);
        }else{
//            printf("Device [checkInject] is passed \n");
        }
    }
}
